<cfparam name="PARAMS.isPDF" default="false">
<cfparam name="PARAMS.debug" default="false">
<cfoutput>
	#dspDocumentHeader()#
	<h2>Initial Screening Assessment/Initial Psychiatric Evaluation <span class="caption">COMAR 10.21.26.06 A</span></h2>
	<cfif PARAMS.key NEQ 0>#dspFormButtons(key=PARAMS.key, action=PARAMS.controller)#</cfif>
	<form class="forms">
		<fieldset>
			<table cellpadding="6">
				<cfloop list="date,diagnosis,assignedCrisisCounselorI,assignedCrisisCounselorII" index="columnName">
					<tr>
						<td class="formLabel">#humanize(columnName, "II")#</td>
						<cfset classStyle = "">
						<cfif columnName IS "Date"><cfset classStyle = "date"></cfif>
						<td>#textFieldTag(id="update-doctorsInformation-#PARAMS.key#-#columnName#", name="update[doctorsInformation][#PARAMS.key#][#columnName#]", class="#classStyle#", value=document.main[columnName][1])#</td>
					</tr>
				</cfloop>		
			</table>
		</fieldset>
		
		<fieldset>
			<legend class="title">Initial Screening Assessment</legend>
	
			<cfset initialScreen = [
					{ 	columnName = 'typeOfAdmission', options = ['Avoid Inpatient Hospitalization','Shorten Inpatient Hospitalization'] },
					{ 	columnName = 'currentMedications', options = [] },
		 			{ 	columnName = 'staffingNeeds1st48Hours', options = ['24hrs on Site','24hrs on Site Awake','One-to-One'] },
					{ 	columnName = 'initialServices', options = ['Provide Safe Environment','Assistance Securing Medications',	'Evaluate Mental Health Needs','Provide mental health crisis stabilization','Develop follow up care plan' ]	}
				]>
		
			<dl>
				<dt><strong>Type Of Admission</strong></dt>
				<dt class="list">
					<div class="radiobutton">
						<cfloop from="1" to="#ArrayLen(initialScreen[1].options)#" index="intOption">
							#dspRadioButton(initialScreen[1].columnName, "validate[required]", intOption, initialScreen[1].options[intOption], "doctors", document.main)#
						</cfloop>
					</div>
				</dt>
				<dt><strong>Current Medications #dspAddButton(2, "currentMedications")#</strong></dt>
				<cfloop query="document.medication">
					<dt class="list">
						Medication: #textFieldTag(id="update-doctors_currentMedications-#id#-name", name="update[doctors_currentMedications][#id#][name]", class="normal2", maxLength="50", value=name)#
					</dt>
				</cfloop>
				<dt><strong>Staffing Needs 1st 48 Hours </strong><span class="caption">COMAR 10.21.26.05 B(1)(c)(i-iii)</span></dt>
				<dt class="list">
					<div class="radiobutton">
						<cfloop from="1" to="#ArrayLen(initialScreen[3].options)#" index="intOption">
							#dspRadioButton(initialScreen[3].columnName, "validate[required]", intOption, initialScreen[3].options[intOption], "doctors", document.main)#
						</cfloop>
					</div>
				</dt>
				<dt><strong>Initial Services to be Provided</strong>: (Review <strong>All</strong> with consumer)</dt>
				<cfloop from="1" to="#ArrayLen(initialScreen[4].options)#" index="intOption">
					<dt class="list">#dspCheckBox(initialScreen[4].columnName, initialScreen[4].options[intOption], intOption, document.main, "doctors")#</dt>
				</cfloop>
			</dl>
			
			<p class="strong" style="margin:2em;">
				I have been explained the rules and discharge procedure for Safe Journey House and I am willing to comply with all rules and regulations of this program.
			</p>
			
			<table align="left" cellpadding="6" width="50%">
				<cfset $checkbox = checkboxTag(id="update-doctors-#PARAMS.key#-consumerSignature", name="update[doctors][#PARAMS.key#][consumerSignature]", value="1")>
				<tr>
					<th class="right">Consumer Signature:</th>
					<td class="left"><cfif document.main.consumerSignature[1] EQ 1>#document.main.consumerName#<cfelse>#$checkbox#</cfif></td>
					<th class="right">Date:</th>
					<td class="left"><input type="text" class="date" /></td>
				</tr>
			</table>
			
			<cfset items = [
					{ label = 'Situation leading to current crisis, <span class="caption">COMAR 10.21.26.03 A(1)</span>:', columnName = 'situationLeadingToCurrentCrisis' },
					{ label = 'Current symptoms of mental illness requiring stabilization:', columnName = 'currentSymptomsOfMentalIllnessRequiringStabilization' },
					{ label = 'Current suicidal/homicidal ideation <strong>and</strong> plan for safety:</p>', columnName = 'currentSuicidal_homicidalIdeationAndPlanForSafety' }
				]>
				
			<dl style="margin-top: 7em;">
				<cfloop array="#items#" index="item">
					<dt>#item.label#</dt>
					<dt class="list">#textAreaTag(id="update-doctors-#PARAMS.key#-#item.columnName#", name="update[doctors][#PARAMS.key#][#item.columnName#]", class="validate[required] normal", content=document.main[item.columnName][1])#</dt>	
				</cfloop>
			</dl>
		</fieldset>		
		<fieldset>
			<legend class="title">Mental Health Treatment <span class="caption">COMAR 10.21.26.060A(2)(a)</span></legend>
			<dl>
				<dt><strong>Hospitalizations</strong>:</dt>
				<dt class="list">
					<span style="margin-right: 2em;">Admissions in Past Year: #textFieldTag(id="update-doctors-#PARAMS.key#-admissionsInPastYear", name="update[doctors][#PARAMS.key#][admissionsInPastYear]", class="small numeric", maxLength="3", value=document.main.admissionsInPastYear)#</span>
					<span> Past 2 Months: #textFieldTag(id="update-doctors-#PARAMS.key#-past2Months", name="update[doctors][#PARAMS.key#][past2Months]", class="small numeric", maxLength="3", value=document.main.past2Months)#</span>
				</dt>
				<dt class="list">
					Lifetime Admissions: 
					<span class="radiobutton">
						#dspRadioButton("lifetimeAdmissions", "validate[required", 1, "0-5", "doctors", document.main)#
						#dspRadioButton("lifetimeAdmissions", "validate[required", 2, "5-10", "doctors", document.main)#
						#dspRadioButton("lifetimeAdmissions", "validate[required", 3, "10+", "doctors", document.main)#
					</span>
				</dt>
				
				<dt class="list">Outpatient Treatment: </dt>
				<dt class="list2">Current #dspAddButton(2, "outpatientTreatment-1")#</dt>
				<cfloop query="document.outpatient">
					<cfif document.outpatient.isLegacy>
						<dt class="list3">
							Outpatient Type: #dspOutpatientTypes(document.outpatient.id, document.outpatient.type)#
							Name: #textFieldTag(id="update-doctors_outpatientTreatments-#id#-name", name="update[doctors_outpatientTreatments][#id#][name]", class="validate[required], normal", value=document.outpatient.name)# 
							Contact Number: #dspPhoneNumber("doctors_outpatientTreatments",document.outpatient.id, "phoneNumber", document.outpatient.phoneNumber)#
						</dt>
					</cfif>
				</cfloop>
				<dt class="list2">
					In Past Year #dspAddButton(2, "outpatientTreatment-2")#
				</dt>
				<cfloop query="document.outpatient">
					<cfif document.outpatient.isLegacy>
						<dt class="list3">
							Outpatient Type: #dspOutpatientTypes(document.outpatient.id, document.outpatient.type)#
							Name: #textFieldTag(id="update-doctors_outpatientTreatments-#id#-name", name="update[doctors_outpatientTreatments][#id#][name]", class="validate[required], normal", value=document.outpatient.name)# 
							Contact Number: #dspPhoneNumber("doctors_outpatientTreatments",document.outpatient.id, "phoneNumber", document.outpatient.phoneNumber)#
						</dt>
					</cfif>
				</cfloop>
			</dl>
		</fieldset>		
		<fieldset>
			<legend class="title">Physical Health</legend>		
			<dl>
				<dt>Current Medical Conditions</dt>
				<dt class="list">#textAreaTag(id="update-doctors-#PARAMS.key#-currentMedicalConditions", name="update[doctors][#PARAMS.key#][currentMedicalConditions]", class="validate[required] normal", content=document.main.currentMedicalConditions)#</dt>
				<dt>
					Consumer is Medically Stable? 
					<span class="radiobutton">
						#dspRadioButton("consumerIsMedicallyStable", "validate[required]", "0", "No", "doctors", document.main)#
						#dspRadioButton("consumerIsMedicallyStable", "validate[required]", "1", "Yes", "doctors", document.main)#
					</span>
				</dt>
				<dt>Allergies #dspAddButton(2, "allergies")#</dt>
				<cfloop query="document.allergies">
					<dt class="list2">
						Type: #textFieldTag(id="update-allergies-#id#-name", name="update[allergies][#id#][name]", class="validate[required]", value=document.allergies.name, maxLength="30")#
					</dt>
				</cfloop>
				<dt>History of any significant medical illnesses/surgeries #dspAddButton(2, "medicalHistory")#</dt>
				<cfloop query="document.medicalHistory">
					<dt class="list2">
						Description: #textFieldTag(id="update-doctors_medicalHistories-#id#-description", name="update[doctors_medicalHistories][#id#][description]", class="validate[required]", value=document.medicalHistory.description, maxLength="30")#
					</dt>
				</cfloop>
			</dl>
		</fieldset>
		<fieldset>
			<legend class="title">Substance Abuse</legend>		
			<p><em>Current/Recent Substance Abuse</em></p>
			<table class="forms" cellpadding="6">
				<tr>
					<cfloop list="Type,Frequency,Last Use" index="CurrentAbuse">
						<th class="title">#CurrentAbuse#</th>
					</cfloop>
					<th class="transparent">
						<div class="btn-group" style="margin: 9px 0;">
							<a class="btn btn-info btn-single addButton" title="Add User">
								<i class="icon-plus icon-white"></i>
							</a>
						</div>
					</th>
				</tr>
				<cfloop query="document.substanceAbuse">	
					<cfif document.substanceAbuse.type>
						<tr>
							<cfloop list="abuseType,frequency,lastUse" index="columnName">
								#textFieldTag(id="update-doctors_substanceAbuses-#id#-#columnName#", name="update[doctors_substanceAbuses][#id#][#columnName#]", class="validate[required] normal", value=document.substanceAbuse[columnName])#
							</cfloop>
						</tr>
					</cfif>
				</cfloop>
			</table><br />
			
			<p><em>History of Substance Abuse</em></p>
			
			<table class="forms" cellpadding="6">
				<tr>
					<cfloop list="Type,Frequency,Clean/Sober Since" index="HistoryAbuse">
						<th class="title">#HistoryAbuse#</th>
					</cfloop>
						<th class="transparent">
							<div class="btn-group" style="margin: 9px 0;">
								<a class="btn btn-info btn-single addButton" title="Add User">
									<i class="icon-plus icon-white"></i>
								</a>
							</div>
						</th>
				</tr>
				<cfloop query="document.substanceAbuse">	
					<cfif document.substanceAbuse.type EQ 0>
						<tr>
							<cfloop list="abuseType,frequency,lastUse" index="columnName">
								#textFieldTag(id="update-doctors_substanceAbuses-#id#-#columnName#", name="update[doctors_substanceAbuses][#id#][#columnName#]", class="validate[required] normal", value=document.substanceAbuse[columnName])#
							</cfloop>
						</tr>
					</cfif>
				</cfloop>
			</table><br />
			
			<dl>
				<cfloop list="familyHistory,physicalOrSexualAbuse,educationalHistory,legalHistory,outsideActivitiesAndInterests,currentSupportiveCollaterals,currentLivingArrangements" index="column">
					<dt>#humanize(humanize(column,"or,and"), "and")# <cfif column IS "currentSupportiveCollaterals"> (Friends, Family, Pastor, etc.)</cfif></dt>
					<dt class="list">
						#textAreaTag(id="update-doctors-#PARAMS.key#-#column#", name="update[doctors][#PARAMS.key#][#column#]", class="validate[required] normal", content=document.main[column][1])#
					</dt>
				</cfloop>
			</dl>
		</fieldset>
		
		<fieldset>
			<legend class="title">Mental Health Examination</legend>
			
			<cfset examination = 
				"generalAppearance,cooperativeness,levelOfPhysicalActivity,quantityAndQualityOfVerbalization,moodAndAffect,thoughtProcesses," &
				"thoughtContent,orientation,attentionAndConcentration,memory,intelligence,judgementAndInsight">
			
			<dl>
				<cfloop list="#examination#" index="columnName">
					<dt>#humanize(humanize(humanize(columnName, "or"), "and"), "of")#</dt>
					<dt class="list">
						#textFieldTag(id="update-doctors-#PARAMS.key#-#columnName#", name="update[doctors][#PARAMS.key#][#columnName#]", class="validate[required] large", value=document.main[columnName][1], maxLength="75")#
					</dt>
				</cfloop>
			</dl>
		</fieldset>
		
		<fieldset>
			<legend class="title">Diagnosis <span class="caption">COMAR 10.21.26.06 C, COMAR 10.21.26.10 B(2)(b)(i-ii)</span></legend>
			
			<table cellpadding="6">
				<tr>
					<td colspan="2">
						<span class="radiobutton">
							#dspRadioButton("affirmedFormulated", "validate[required]", "0", "Affirmed", "doctors", document.main)#
							#dspRadioButton("affirmedFormulated", "validate[required]", "1", "Formulated", "doctors", document.main)#
						</span>
					<td>
				</tr>
				<cfloop list="axisI,axisII,axisIII,axisIV,axisV" index="columnName">
					<tr>
						<th valign="top">#humanize(columnName)#</th>
						<td valign="top">
							<cfif columnName IS "axisI">
								#dspAxisCodes("doctors", PARAMS.key, "axisI", document.main.axisI)#
							<cfelseif ListFindNoCase("axisII,axisIII", columnName)>
								#textAreaTag(id="update-doctors-#PARAMS.key#-#columnName#", name="update[doctors][#PARAMS.key#][#columnName#]", class="validate[required] small", content=document.main[columnName][1])#
							<cfelse>
								<cfif columnName IS "axisIV"><cfset $attr = { class = "normal1", maxLength="15" }><cfelse><cfset $attr = { class="small numeric", maxLength="3" }></cfif>
								#textFieldTag(id="update-doctors-#PARAMS.key#-#columnName#", name="update[doctors][#PARAMS.key#][#columnName#]", class="validate[required] #$attr.class#", value=document.main[columnName][1], maxLength="#$attr.maxLength#")#
							</cfif>						
						</td>
					</tr>
				</cfloop>
			</table><br />
			
			<cfset columnName = ["rationaleForFormulatedDiagnosis","recommendationsForTreatmentAtSJH","currentMedicalConditionsRequiringMonitoring","planToMonitorCondition"]>
			<dl>
				<dt>#humanize(columnName[1], "for")#:</dt>
				<dt class="list">#textAreaTag(id="update-doctors-#PARAMS.key#-#columnName[1]#", name="update[doctors][#PARAMS.key#][#columnName[1]#]", class="validate[required] normal", content=document.main[columnName[1]][1])#</dt>
				<dt>#humanize(humanize(columnName[2], "for"), "at")# <span class="caption">COMAR 10.21.26.06 A(5)</span>:</p>
				<dt class="list">#textAreaTag(id="update-doctors-#PARAMS.key#-#columnName[2]#", name="update[doctors][#PARAMS.key#][#columnName[2]#]", class="validate[required] normal", content=document.main[columnName[2]][1])#</dt>
				<dt>#humanize(columnName[3])# <span class="caption">COMAR 10.21.26.06 A(5)</span>:</p>
				<dt class="list">#textAreaTag(id="update-doctors-#PARAMS.key#-#columnName[3]#", name="update[doctors][#PARAMS.key#][#columnName[3]#]", class="validate[required] normal", content=document.main[columnName[3]][1])#</dt>
				<dt>#humanize(columnName[4], "to")# Including Tool(s) & Frequency <span class="caption">COMAR 10.21.26.06 A(5)</span>:</p>
				<dt class="list">#textAreaTag(id="update-doctors-#PARAMS.key#-#columnName[4]#", name="update[doctors][#PARAMS.key#][#columnName[4]#]", class="validate[required] normal", content=document.main[columnName[4]][1])#</dt>
			</dl>
			
			<table width="450px" cellpadding="6">
				<tr>
					<th class="right">Physicial Signature:</th>
					<td>#textFieldTag(id="update-doctors-#PARAMS.key#-physicianSignature", name="update[doctors][#PARAMS.key#][physicianSignature]", class="validate[required] normal2", value=document.main.physicianSignature, maxLength="30")#</td>
				</tr>
				<tr>
					<th class="right">Date:</th>
					<td>#textFieldTag(id="update-doctors-#PARAMS.key#-physicianSignatureDate", name="update[doctors][#PARAMS.key#][physicianSignatureDate]", class="validate[required] date", value=document.main.physicianSignatureDate)#</td>
				</tr>
				<tr>
					<th class="right">Consumer Name:</th>
					<td>#document.main.consumerName#</td>
				</tr>
			</table>
		</fieldset>
	</form>
	<cfif PARAMS.key NEQ 0>#dspFormButtons(key=PARAMS.key, action=PARAMS.controller)#</cfif>
</cfoutput>

<script type="text/javascript">
	$('body').on('click', '.addButton', function () {
		var $type = $(this).attr('column-type');
		var $id = $(this).attr('column-id');
		
		alert($type);
		
		switch($type) {
			case 'currentMedications':
				var $e = $('<dt class="list">' + $elements.input.replace(/\[table\]/g, "doctors_currentMedications").replace(/\[id\]/g, $id).replace(/\[column\]/g, $type) + '</dt>');
				$(this).parent().after($e);
				break;
			case 'outpatientTreatment-1': case 'outpatientTreatment-2':
				var $o = $elements.input.replace(/\[table\]/g, "doctors_outpatientTreatments").replace(/\[id\]/g, $id);
				var $e = $('<dt class="list3">Outpatient Type:' + ' Name:' + $o.replace(/\[column\]/g, 'name') + ' Contact Number:'  + $o.replace(/\[column\]/g, 'phoneNumber') + '</dt>');
				$(this).parent().after($e);
				break;
			case 'allergies':
				var $e = $('<dt class="list">Type:' + $elements.input.replace(/\[table\]/g, "allergies").replace(/\[id\]/g, $id).replace(/\[column\]/g, 'name') + '</dt>');
				$(this).parent().after($e);
				break;
			case 'medicalHistory':
				var $e = $('<dt class="list">Description:' + $elements.input.replace(/\[table\]/g, "doctors_medicalHistory").replace(/\[id\]/g, $id).replace(/\[column\]/g, 'description') + '</dt>');
				$(this).parent().after($e);
				break;
			default:
				var $o = $elements.input.replace(/\[table\]/g, "doctors_substanceAbuse").replace(/\[id\]/g, $id);
				var $e = $('<tr><td>' + $o.replace(/\[column\]/g, 'abuseType') + '</td><td>' + $o.replace(/\[column\]/g, 'frequencyID') + '</td><td>' + $o.replace(/\[column\]/g, 'lastUseDate') + '</td></tr>');
				$(this).parent().parent().parent().after($e);
				break;
		}
	});
</script>
